package com.now.printer.utils;

import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.now.printer.ui.activity.MainActivity;
import com.xuexiang.xutil.XUtil;
import com.xuexiang.xutil.app.ActivityUtils;

import androidx.annotation.NonNull;

/**
 * @author XUE
 * @since 2019/4/1 11:25
 */
public final class Utils {

    public final static String UPDATE_URL = "https://gitee.com/xuexiangjys/XUI/raw/master/jsonapi/update_api.json";

    private Utils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 初始化主题
     */
    public static void initTheme(Activity activity) {
//        if (SettingSPUtils.getInstance().isUseCustomTheme()) {
//            activity.setTheme(R.style.CustomAppTheme);
//        } else {
//            XUI.initTheme(activity);
//        }
    }

    /**
     * 同步首页状态,未启动就启动
     */
    public static void syncMainPageStatus() {
        if (!XUtil.getActivityLifecycleHelper().isActivityExist(MainActivity.class)) {
            ActivityUtils.startActivity(MainActivity.class);
        }
    }

    /**
     * 2.软键盘是否显示(有输入框)
     *
     * @param context
     * @param mEditText
     */
    public static boolean isShowSoftKeyboard(@NonNull Context context,
                                             @NonNull EditText mEditText) {
        InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

        if (inputMethodManager.isActive(mEditText)) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * 2.显示软键盘(有输入框)
     *
     * @param context
     * @param mEditText
     */
    public static void showSoftKeyboard(@NonNull Context context,
                                        @NonNull EditText mEditText) {
        InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }


    /**
     * 3.隐藏软键盘(有输入框)
     *
     * @param context
     * @param mEditText
     */
    public static void hideSoftKeyboard(@NonNull Context context,
                                        @NonNull EditText mEditText) {
        InputMethodManager inputmanger = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    }

}
